<?php
namespace adminmatrix\admin\logic;
use app\Request;
use think\response\Json;

class BaseLogic implements interfaceLogic
{

    public function save(Request $request): bool
    {
        // TODO: Implement save() method.
        return $this->model->save($request->post());
    }


    public function update(Request $request): bool
    {
        // TODO: Implement update() method.
        $id = $request->put('id');
        $data = $request->put();
        $reslut = $this->model->where('id' , $id)->findOrEmpty();
        if($reslut->isEmpty())
        {
            throw new \Exception('数据不存在');
        }
        
        return $reslut->save($data);
    }

    public function delete(Request $request): bool
    {
        // TODO: Implement delete() method.
        $id = $request->get('id');
        $reslut = $this->model->where('id' , $id)->findOrEmpty();
        if($reslut->isEmpty())
        {
            throw new \Exception('数据不存在');
        }
        return $reslut->delete();
    }

    public function get(Request $request , ?array $where = []): mixed
    {
        // TODO: Implement get() method.
        $admin = $this->model->where($where)->findOrEmpty();
        return $admin;
    }

    public function set(string $name, mixed $value): Json
    {
        // TODO: Implement set() method.
    }

    public function value(string $name): Json
    {
        // TODO: Implement value() method.
    }
}